package com.purchase.ml.task.order;

import com.purchase.ml.exception.BizException;
import com.purchase.ml.service.order.SysOrderService;
import com.purchase.ml.service.sdk.Ipay88Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Created by kyyang on 2021/3/2 19:03
 */
@Component
@Slf4j
public class OrderCollectScheduler {


    @Autowired
    private SysOrderService sysOrderService;
    @Autowired
    private Ipay88Service ipay88Service;

    /**
     * @description: 每天 0:30 执行昨日订单汇总
     * @author kyyang
     * @date 2021/3/2 19:05
     * @version 1.0
     */
//    @Scheduled(cron = "0 30 0 * * ?")
   // @Scheduled(cron = "0 0/1 * * * ? ")
   // @PostConstruct
    public void  jobOrderCollect(){
        try {
            log.info("开始执行昨日订单汇总任务");
            long start = System.currentTimeMillis();
            sysOrderService.jobOrderCollect();
            long end = System.currentTimeMillis();
            log.info("昨日订单汇总任务执行完成，耗时:[{}] 秒",(end-start)/1000);
        }catch (Exception e){
            throw new BizException("900","昨日订单汇总任务失败，原因:",e);
        }


    }

    //每10秒查询一次订单的支付状态：查询的数据只有 00 没有细节 弃用
//    @Scheduled(cron = "0/10 * * * * ?")
    public void  QueryPayOrder(){
        ipay88Service.popObjFromRedisAndQuery(10);
    }

}
